﻿using MediatR;
using Microsoft.AspNetCore.Components.Routing;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.Produce.WorkCenter_;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Set.API.Application.Commands.Week1.Process_CRUD
{
    /// <summary>
    /// 获取工作中心表数据
    /// </summary>
    public class GetWorkCenterHandler : IRequestHandler<GetWorkCenterCommand, Result>
    {
        public GetWorkCenterHandler(IBaseRepository<WorkCenter> workCenterRepository)
        {
            WorkCenterRepository = workCenterRepository;
        }

        public IBaseRepository<WorkCenter> WorkCenterRepository { get; set; }
        public async Task<Result> Handle(GetWorkCenterCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() {Code=(int)CommonErrorCodes.Search };
            var sql = "select * from workCenters;";
            var WorkCenterData = WorkCenterRepository.GetAll(sql).ToList();
            if (WorkCenterData != null)
            {
                result.Data = WorkCenterData;
                result.Code = (int)CommonErrorCodes.Success;
                return result;
            }
            else
            { 
                return result;
            }
        }
    }
}
